import math


# n: 多边形边数
def factorial(n):
    """阶乘"""
    i = 1
    s = 1   # 由于设置了“乘法元”为1，所以n=0时不需要单独计算
    while (i <= n):
        s = s * i
        i = i + 1
    return s


def sin_np(x, d=1E-9):
    n = 1
    s = 0
    last = d
    while (abs(s - last) >= d):
        last = s
        s = s + (-1)**(n - 1) * (x**(2*n - 1)) / factorial(2*n - 1)
        n = n + 1
    return s


def cos_np(x, d=1E-9):
    n = 1
    s = 0
    last = d
    while (abs(s - last) >= d):
        last = s
        s = s + (-1)**(n - 1) * (x**(2*n - 2)) / factorial(2*n - 2)
        n = n + 1
    return s


def pi(n):
    pi = n * sin_np(math.pi / (n))
    return pi


pi_list = []

i = 3
N = 100
while (i < N-1):
    i = i + 1
    # pi_list[i] = pi(i)
    pi_list.append(pi(i))


for i in pi_list:
    print(i)

print("循环31415次", pi(31415))
